#ifndef _CMS_INTERFACE_H_
#define _CMS_INTERFACE_H_

#include "Include.h"
#include "Data.h"
#include "Packet.h"

class CMS_OBJECT_DATA
{
public:
	std::string objectId;

public:
	std::string video;
	std::string image;
	std::string sound;
	std::string curve;
	std::string opacity;
	std::string blending;

	CMS_OBJECT_DATA()
	{
		objectId = "";
		video = "";
		image = "";
		sound = "";
		curve = "";
		opacity = "";
		blending = "";
	};

	CMS_OBJECT_DATA(const std::string& objId , const Json::Value& v)
	{
		this->objectId = objId;

		video = PACKET_BASE::GetStringS(v, "video");
		image = PACKET_BASE::GetStringS(v, "image");
		sound = PACKET_BASE::GetStringS(v, "sound");
		curve = PACKET_BASE::GetStringS(v, "curve");
		opacity = PACKET_BASE::GetStringS(v, "opacity"); 
		blending = PACKET_BASE::GetStringS(v, "blending");

	};

	CMS_OBJECT_DATA(const CMS_OBJECT_DATA& data)
	{
		this->objectId	= data.objectId;

		this->video	= data.video;
		this->image	= data.image;
		this->sound	= data.sound;
		this->curve	= data.curve; 
		this->opacity	= data.opacity; 
		this->blending	= data.blending;
	}

    const CMS_OBJECT_DATA& operator=(const CMS_OBJECT_DATA & data)
	{
		if (this != &data) 
		{
			this->objectId	= data.objectId;

			this->video	= data.video;
			this->image	= data.image;
			this->sound	= data.sound;
			this->curve	= data.curve; 
			this->opacity	= data.opacity; 
			this->blending	= data.blending;
		}
		return *this;	
	}


public:
	static std::map<std::string , CMS_OBJECT_DATA> gCMSObjectMap;
	static ACE_Thread_Mutex	gCMSObjectLock;


	static std::vector<std::string> GetToGetObjectList(std::set<std::string>& objIdSet); 
	static bool GetObjectData(const std::string& objId , CMS_OBJECT_DATA& data); 
	static int PutObjectList(const Json::Value& v );
	static std::string GetBGMPath(const std::string& bgmId);


};

class CMS_EFFECT_DATA
{
public:
	std::string object_path;
	std::string sound_path;

	CMS_EFFECT_DATA()
	{
		object_path = sound_path = "";
	};
	CMS_EFFECT_DATA(const std::string& object_path , const std::string& sound_path)
	{
		if(object_path.length() > 0)
			this->object_path = Settings::GetSettings()->OBJECT_DIR + object_path;
		if(sound_path.length() > 0)
			this->sound_path = Settings::GetSettings()->OBJECT_DIR + sound_path;
	};

	CMS_EFFECT_DATA(const CMS_EFFECT_DATA& data)
	{
		this->object_path = data.object_path;
		this->sound_path = data.sound_path;
	}

    const CMS_EFFECT_DATA& operator=(const CMS_EFFECT_DATA & data)
	{
		if (this != &data) 
		{
			this->object_path = data.object_path;
			this->sound_path = data.sound_path;
		}
		return *this;	
	}

};

class CMS_FILTER_DATA
{
public:
	std::string filter_path;
	std::string blending_type;
	double opacity;
	std::string curve_path;

	CMS_FILTER_DATA()
	{
		filter_path = "";
		blending_type = "";
		opacity = 0.0;
		curve_path = "";
	};

	CMS_FILTER_DATA(const std::string& filter_path , const std::string& blending_type , double opacity , const std::string& curve_path)
	{
		if(filter_path.length() > 0)
			this->filter_path = Settings::GetSettings()->OBJECT_DIR + filter_path;

		this->blending_type = blending_type;
		this->opacity = opacity;

		if(curve_path.length() > 0)
			this->curve_path = Settings::GetSettings()->OBJECT_DIR + curve_path;
	};

	CMS_FILTER_DATA(const CMS_FILTER_DATA& data)
	{
		this->filter_path = data.filter_path;
		this->blending_type = data.blending_type;
		this->opacity = data.opacity;
		this->curve_path = data.curve_path;
	}

    const CMS_FILTER_DATA& operator=(const CMS_FILTER_DATA & data)
	{
		if (this != &data) 
		{
			this->filter_path = data.filter_path;
			this->blending_type = data.blending_type;
			this->opacity = data.opacity;
			this->curve_path = data.curve_path;
		}
		return *this;	
	}

};

class CMSInterface
{
public:

	static bool Connect(ACE_SOCK_Stream& stream);
	static bool Disconnect(ACE_SOCK_Stream & stream);

	static std::string GetCMSJsonString(const std::string& addr);
	static std::string PostCMSJsonString(const std::string& addr  ,  PACKET_BASE& content);
	static std::string PostCMSJsonString(const std::string& addr  ,  const std::string& name , const std::string& value);

	static std::string Snd2CMS(const std::string& req);

public: 

	static bool Succeeded(const std::string& json_str);

	static int GetJobList(int max_size , std::vector<_JOB_INFO> & v);

	static bool CancelAll();

	static bool SucceededJob(ReservedInfo& info);
	static bool FailedJob(ReservedInfo& info);

	static bool GetObjectInfoList(std::set<std::string>& setObjectId);
	static int GetWaitingJobCount();

public:

	static CMS_EFFECT_DATA GetEffectData(const std::string& effect_id);
	static CMS_FILTER_DATA GetFilterData(const std::string& filter_id);

	static std::string RemoveChunkSize(std::string& body); 

public:

	static bool RegistFiles();

};


#endif
